
export function importAll(modulesFiles) {
  // const modulesFiles = require.context( path, true, /\.vue$/)
  const modules = modulesFiles.keys().reduce((modules, modulePath) => {
    const moduleName = getModuleName(modulePath)

    const value = modulesFiles(modulePath)
    modules[moduleName] = value.default
    return modules
  }, {})

  return modules
}

export function getModuleName(path) {
  let name = ''
  if (path.endsWith('index.vue')) {
    name = path.replace(/^\.\//, '').replace(/(\/index)?\.vue$/, '')
  } else {
    name = path.match(/\/([a-zA-Z0-9]+?)\.vue$/)[1]
  }
  return name
}

export function getDirectiveName(path) {
  let name = ''
  if (path.endsWith('index.js')) {
    name = path.replace(/^\.\//, '').replace(/(\/index)?\.js$/, '')
  } else {
    name = path.match(/\/([a-zA-Z0-9]+?)\.js$/)[1]
  }
  return name
}

export default importAll
